#include "tim_app.h"

void Tim_set_duty(uint16_t duty)
{
    TIM2->CCR2 = (TIM2->ARR +1 )* (duty / 100.0f);
}

void Tim_set_freq(uint16_t freq)
{
    uint32_t Clock_freq = 1000000;

    uint32_t value = Clock_freq / freq - 1;

    TIM2->CCR2 = (value + 1) * (TIM2->CCR2 / TIM2->ARR);

    TIM2->ARR = value;

    TIM2->EGR = TIM_EGR_UG;
}


uint32_t adc_buffer[2][30];
float adc_value[2];
void tim_proc(void)
{
	for(int i=0;i<30;i++)
	{
		adc_value[0] += adc_buffer[0][i];
		adc_value[1] += adc_buffer[1][i];
	}
		adc_value[0] = adc_value[0]/30.0f/4096*3.3f;
		adc_value[1] = adc_value[1]/30.0f/4096*3.3f;
	
}

